<?php

	class product_fit_DAO extends CI_Model{

		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		
		public function search($keyword){
			$where = "vi_name like '%{$keyword}%' OR en_name like '%{$keyword}%'";
			$this->db->where($where);
			$query = $this->db->get("product_fit");
			return $query->result_array();
		}
		
		public function getAllList(){
			$query = $this->db->get("product_fit");
			return $query->result_array();
		}

		public function getAll($category_level_2_id){
			$this->db->where('category_level_2_id', $category_level_2_id);
			$query = $this->db->get("product_fit");
			return $query->result_array();
		}
		
		public function get($id){
			$this->db->where('id', $id);
			$query = $this->db->get("product_fit");
			if($query->num_rows() == 1){
				$tempQuery = $query->result();
				return $tempQuery[0];
			} else {
				return null;
			}
		}
		
		public function add($category){
			$this->db->insert("product_fit", $category);
			return ($this->db->affected_rows() != 1) ? false : true;
		}
		
		public function update($id, $category_level_2_id, $vi_name, $en_name, $description){
			$data = array(
				'category_level_2_id' => $category_level_2_id,
				'vi_name' => $vi_name,
				'en_name' => $en_name,
				'description' => $description
            );
			$this->db->where('id', $id);
			$this->db->update('product_fit', $data);
			return ($this->db->affected_rows() != 1) ? false : true;
		}
		
		public function delete($id){
			$this->db->where('id', $id);
			$this->db->delete('product_fit');
			return ($this->db->affected_rows() != 1) ? false : true;
		}
	}

?>